{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 14\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters._**\n",
    "\n",
    "> **_Suppose the following input is supplied to the program:_**\n",
    "\n",
    "\n",
    "Hello world!\n",
    "\n",
    "\n",
    "> **_Then, the output should be:_**\n",
    "\n",
    "\n",
    "UPPER CASE 1\n",
    "\n",
    "LOWER CASE 9\n",
    "\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "word = input()\n",
    "upper, lower = 0, 0\n",
    "\n",
    "for i in word:\n",
    "    if \"a\" <= i and i <= \"z\":\n",
    "        lower += 1\n",
    "    if \"A\" <= i and i <= \"Z\":\n",
    "        upper += 1\n",
    "\n",
    "print(\"UPPER CASE {0}\\nLOWER CASE {1}\".format(upper, lower))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "word = input()\n",
    "upper, lower = 0, 0\n",
    "\n",
    "for i in word:\n",
    "    lower += i.islower()\n",
    "    upper += i.isupper()\n",
    "\n",
    "print(\"UPPER CASE {0}\\nLOWER CASE {1}\".format(upper, lower))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "word = input()\n",
    "upper = sum(\n",
    "    1 for i in word if i.isupper()\n",
    ")  # sum function cumulatively sum up 1's if the condition is True\n",
    "lower = sum(1 for i in word if i.islower())\n",
    "\n",
    "print(\"UPPER CASE {0}\\nLOWER CASE {1}\".format(upper, lower))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# solution by Amitewu\n",
    "\n",
    "string = input(\"Enter the sentense\")\n",
    "upper = 0\n",
    "lower = 0\n",
    "for x in string:\n",
    "    if x.isupper() == True:\n",
    "        upper += 1\n",
    "    if x.islower() == True:\n",
    "        lower += 1\n",
    "\n",
    "print(\"UPPER CASE: \", upper)\n",
    "print(\"LOWER CASE: \", lower)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 15\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a._**\n",
    "\n",
    "> **_Suppose the following input is supplied to the program:_**\n",
    "\n",
    "\n",
    "9\n",
    "\n",
    "\n",
    "> **_Then, the output should be:_**\n",
    "\n",
    "\n",
    "11106\n",
    "\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = input()\n",
    "total, tmp = 0, str()  # initialing an integer and empty string\n",
    "\n",
    "for i in range(4):\n",
    "    tmp += a  # concatenating 'a' to 'tmp'\n",
    "    total += int(tmp)  # converting string type to integer type\n",
    "\n",
    "print(total)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**\n",
    "\n",
    "```python\n",
    "a = input()\n",
    "total = int(a) + int(2*a) + int(3*a) + int(4*a)  # N*a=Na, for example  a=\"23\", 2*a=\"2323\",3*a=\"232323\"\n",
    "print(total)\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
